package com.xmy.study.service.impl;

import com.xmy.study.constants.MqConstants;
import com.xmy.study.entity.ChaPlan;
import com.xmy.study.respons.ChaStudyPlan;
import com.xmy.study.service.IMqPushService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MqPushServiceImpl implements IMqPushService {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Override
    public boolean useGoodsNum(ChaPlan chaPlan){
        try {
            rabbitTemplate.convertAndSend(MqConstants.EXCHANGE_SYNC_STORE_GOODS_USE_NUM_FANOUT, null, chaPlan);
        } catch (Exception e) {
            return false;
        }
        return true;
    }

    /**
     * 判断是否通关，已通关不算应到
     */
    @Override
    public void chaStudyPlanAdd(ChaStudyPlan chaStudy) {
        try{
            rabbitTemplate.convertAndSend(MqConstants.EXCHANGE_CHA_STUDY_STATUS, null, chaStudy);
        }catch (Exception e){
            //System.out.println("out:"+e.getMessage());
        }
    }


    @Override
    public void chaStudyPlanAccuracyAdd(ChaStudyPlan chaStudy) {
        try{
            rabbitTemplate.convertAndSend(MqConstants.EXCHANGE_CHA_STUDY_ACCURACY_FANOUT, null, chaStudy);
        }catch (Exception e){
            //System.out.println("out:"+e.getMessage());
        }
    }
}
